<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/13 0013
 * Time: 10:12
 */

namespace App\Content\Repositories;

use App\Content\Contracts\ArticleClassInterface;
use App\Content\Models\ArticleClassModel;
use Illuminate\Support\Facades\Request;

/**
 * 用户新闻列表
 * Class DbGoodsRepository
 * @package App\Shop\Repositories
 */
class DbArticleClassRepository implements ArticleClassInterface
{
    /**
     * 新闻模型
     * @return ArticleClassModel
     */
    public function getArticleClassModel(){
        return app()->make(ArticleClassModel::class);
    }

    /**
     * 获取菜单列表
     * @param $where
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|mixed
     */
    public function getClassMenuList($where){
        $request=Request::instance();
        $limit=empty($request->input("limit"))?10:$request->input("limit");
        return $this->getArticleClassModel()->newQuery()->where($where)->paginate($limit);
    }

    /**
     * 获取信息列表
     * @param $where
     * @return mixed|void
     */
    public function getInfo($where){
        return $this->getArticleClassModel()->newQuery()->where($where)->first();
    }


    /**
     * 删除数据
     * @param $data
     * @return mixed|void
     */
    public function delData($where){
      return $this->getArticleClassModel()->newQuery()->where($where)->delete();
    }

    /**
     * 配置添加与更新
     * @param $data
     * @return mixed|void
     */
    public function updateOrCreateClassClassData($data)
    {
        $data['status']=empty($data["status"])?0:1;
        $id = $data["id"];
        unset($data["id"]);
        $data=$this->getArticleClassModel()->filter($data);
        return $this->getArticleClassModel()->newQuery()->updateOrCreate(["id"=>$id],$data);
    }
}